package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.New.NewsDetailsActivity;
import com.example.myapplication.Outpatientappointment.HospitalDetailsActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.BingnewlistBean;
import com.example.myapplication.ShuJu.OutpatientlistBean;

import java.util.List;

public class OutpatientlistApter extends RecyclerView.Adapter<OutpatientlistApter.MyHolder>{
    private Context context;
    private List<OutpatientlistBean.RowsBean> list;

    public OutpatientlistApter(Context context, List<OutpatientlistBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public OutpatientlistApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_outpatientlist,null);
        return new OutpatientlistApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull OutpatientlistApter.MyHolder holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getImgUrl()).into(holder.img_Outpatientlist);
        holder.img_Outpatientlist.setScaleType(ImageView.ScaleType.FIT_XY);
        holder.title_Outpatientlist.setText(list.get(position).getHospitalName());
        holder.xi_Outpatientlist.setText("星级:"+list.get(position).getLevel());
        holder.re_Outpatientlist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, HospitalDetailsActivity.class);
                intent.putExtra("HospitalDetailsActivityID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView img_Outpatientlist;
        TextView title_Outpatientlist;
        TextView xi_Outpatientlist;
        RelativeLayout re_Outpatientlist;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            img_Outpatientlist = itemView.findViewById(R.id.img_Outpatientlist);
            title_Outpatientlist = itemView.findViewById(R.id.title_Outpatientlist);
            xi_Outpatientlist = itemView.findViewById(R.id.xi_Outpatientlist);
            re_Outpatientlist = itemView.findViewById(R.id.re_Outpatientlist);
        }
    }
}


